package cn.fl.product.service.impl;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import cn.cmm.base.framework.logger.eum.LogExceptionEnum;
import cn.cmm.base.framework.logger.eum.LogOperEnum;
import cn.fl.mfr.base.vo.BaseMfrBscInfoVO;
import fl.constant.facade.framework.constant.BusinessIdConstant;
import fl.spl.base.mfr.dto.BaseMfrRlPsnDTO;
import fl.spl.facade.mfr.api.IMfrOrgRApiService;
import fl.spl.facade.mfr.condition.MfrOrgRQC;
import fl.spl.facade.mfr.dto.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.dubbo.rpc.RpcException;
import com.alibaba.fastjson.JSONObject;

import cmm.comm.facade.framework.api.ISysDictionaryApiService;
import cmm.comm.facade.framework.dto.SysDictionaryDTO;
import cmm.mid.core.framework.dto.DataResultDTO;
import cmm.mid.core.framework.page.KeyValueVO;
import cmm.mid.core.framework.page.Pager;
import cmm.user.facade.system.api.ISysOrgApiService;
import cmm.user.facade.system.dto.SysOrgDTO;
import cn.cmm.base.framework.constant.BaseConstant;
import cn.cmm.base.framework.constant.BaseExceptionConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.CollectionUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.mfr.web.transform.MfrFlowSHVOTransform;
import cn.fl.mfr.web.vo.MfrFlowSHVO;
import cn.fl.product.service.IMfrInfoService;
import cn.fl.product.transform.MfrInfoVOTransform;
import cn.fl.product.vo.MfrInfoVO;
import cn.fl.system.transform.SysUlFilesRecVOTransform;
import cn.fl.system.vo.SysUlFilesRecVO;
import fl.flow.facade.flow.api.IFlowQueryApiService;
import fl.flow.facade.flow.condition.SysFlowSHQueryCondition;
import fl.flow.facade.flow.dto.FlowStartParamsDTO;
import fl.flow.facade.flow.dto.SysFlowSHDTO;
import fl.spl.base.mfr.dto.BaseMfrBscInfoDTO;
import fl.spl.facade.framework.annotation.FieldApply;
import fl.spl.facade.framework.constant.SplSystemConstant;
import fl.spl.facade.framework.enums.SplAudStsCdEnum;
import fl.spl.facade.mfr.api.IMfrInfoApiService;
import fl.spl.facade.mfr.api.IMfrInfoModApiService;
import fl.spl.facade.mfr.api.IMfrInfoModDtlApiService;
import fl.spl.facade.mfr.condition.MfrInfoModDtlQC;
import fl.spl.facade.mfr.condition.MfrInfoModQC;
import fl.spl.facade.mfr.condition.MfrInfoQueryCondition;
import fl.spl.facade.mfr.constant.MfrInfoConstant;

/**
 * @Description: 厂商信息表 客户端服务层接口实现
 * 业务层方法名称前缀：
 * 新增：add*
 * 删除：remove*
 * 修改：modify*
 * 批量：batch*
 * 查询对象：select* get*
 * 查询集合：search*
 */
@Service
public class MfrInfoServiceImpl implements IMfrInfoService {

	/**
	 * 厂商暴露服务API
	 */
	@Autowired
	private IMfrInfoApiService mfrInfoApiService;

	@Autowired
	private ISysOrgApiService sysOrgApiService;

	@Autowired
	private ISysDictionaryApiService sysDictionaryApiService;

	@Autowired
	private IFlowQueryApiService flowQueryApiService ;

	@Autowired
	private IMfrInfoModApiService mfrInfoModApiService ;

	@Autowired
	private IMfrInfoModDtlApiService mfrInfoModDtlApiService;

	@Autowired
	private IMfrOrgRApiService mfrOrgRApiService;

	@Override
	public MfrInfoVO selectById(Long id, String currentOrgCd) throws BaseException{
		if(StringUtils.isEmpty(id)){
			BaseLogUtils.newWebLogger("根据主键查询厂商信息失败,主键参数为空").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_PROD_MANAGER_CD)
					.setWarning(false)
					.warn(LogExceptionEnum.COMMON_CODE_0002);
			throw new BaseException(BaseExceptionConstant.COMMON_0001,BaseExceptionConstant.COMMON_0001_NAME);
		};
		MfrInfoDTO dto = this.mfrInfoApiService.selectPrdMfrInfoById(id,CurrentThreadContext.getCurrentSysCd(),currentOrgCd);
		return this.setDict(MfrInfoVOTransform.toVO(dto));
	}

	@Override
	public Long add(MfrInfoVO entity, String currentOrgCd) throws BaseException{
		if(null == entity){
			BaseLogUtils.newWebLogger("新增厂商失败,厂商对象参数为空").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_PROD_MANAGER_CD)
					.setWarning(false)
					.warn(LogExceptionEnum.COMMON_CODE_0002);
			throw new BaseException(BaseExceptionConstant.COMMON_0001,BaseExceptionConstant.COMMON_0001_NAME);
		}
		return this.mfrInfoApiService.addPrdMfrInfo(MfrInfoVOTransform.toDTO(entity),CurrentThreadContext.getCurrentSysCd(),currentOrgCd);
	}

	@Override
	public boolean modify(MfrInfoVO entity, String currentOrgCd) throws BaseException{
		if(null == entity){
			BaseLogUtils.newWebLogger("修改厂商失败,主键参数为空").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_PROD_MANAGER_CD)
					.setWarning(false)
					.warn(LogExceptionEnum.COMMON_CODE_0002);
			throw new BaseException(BaseExceptionConstant.COMMON_0001,BaseExceptionConstant.COMMON_0001_NAME);
		}
		return this.mfrInfoApiService.modifyPrdMfrInfo(MfrInfoVOTransform.toDTO(entity),CurrentThreadContext.getCurrentSysCd(),currentOrgCd);
	}

	@SuppressWarnings("unchecked")
	@Override
	public Pager searchListPage(Pager page) throws BaseException{
		if(null == page){
			page = new Pager();
		}
		page = this.mfrInfoApiService.searchPrdMfrInfoListPage(page,CurrentThreadContext.getCurrentSysCd(),CurrentThreadContext.getCurrentOrgCd());
		List<MfrInfoDTO> resultList = (List<MfrInfoDTO>) page.getResultList();
		BaseLogUtils.newWebLogger("服务层返回的查询结果").setLogOperType(LogOperEnum.RESP)
				.setSysCd(CurrentThreadContext.getCurrentSysCd())
				.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
				.setBussinessId(BusinessIdConstant.LOG_PROD_MANAGER_CD)
				.setWarning(false)
				.setKeys("resultList", JSONObject.toJSONString(resultList))
				.info();
		page.setResultList(MfrInfoVOTransform.toVOList(resultList));
//		page.setResultList(this.setDict(MfrInfoVOTransform.toVOList(resultList)));
		return page;
	}

	@Override
	public List<KeyValueVO> searchSelectOrgCdlist() throws BaseException {
		List<SysOrgDTO> sysOrgDTOList = this.sysOrgApiService.searchListByOrgTypCd(CurrentThreadContext.getCurrentSysCd());
		if(CollectionUtils.isEmpty(sysOrgDTOList)){
			BaseLogUtils.newWebLogger("查询厂商添加事业部项结果为空").setLogOperType(LogOperEnum.RESP)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_PROD_MANAGER_CD)
					.setWarning(false)
					.warn(LogExceptionEnum.COMMON_CODE_0002);
			throw new BaseException(BaseExceptionConstant.COMMON_0001,BaseExceptionConstant.COMMON_0001_NAME);
		}
		List<KeyValueVO> kvList = new ArrayList<KeyValueVO>();
		for (SysOrgDTO sysOrgDTO : sysOrgDTOList) {
			KeyValueVO kv = new KeyValueVO();
			kv.setKey(String.valueOf(sysOrgDTO.getOrgCd()));//组织架构代码
			kv.setValue(sysOrgDTO.getOrgNm());//组织架构名称
			kvList.add(kv);
		}

		return kvList;
	}

	@Override
	public boolean removeByIds(List<Long> ids) throws BaseException {
		if(CollectionUtils.isEmpty(ids)){
			BaseLogUtils.newWebLogger("删除厂商失败,主键参数为空").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_PROD_MANAGER_CD)
					.setWarning(false)
					.warn(LogExceptionEnum.COMMON_CODE_0002);
			throw new BaseException(BaseExceptionConstant.COMMON_0001,BaseExceptionConstant.COMMON_0001_NAME);
		}
		return this.mfrInfoApiService.removePrdMfrInfoByIds(ids, CurrentThreadContext.getCurrentSysCd(),CurrentThreadContext.getCurrentOrgCd());
	}

	@Override
	public boolean enAblePrdMfrInfo(Long id) throws BaseException {
		if(null == id){
			BaseLogUtils.newWebLogger("启用厂商失败,主键参数为空").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_PROD_MANAGER_CD)
					.setWarning(false)
					.warn(LogExceptionEnum.COMMON_CODE_0002);
			throw new BaseException(BaseExceptionConstant.COMMON_0001,BaseExceptionConstant.COMMON_0001_NAME);
		}
		return this.mfrInfoApiService.enAblePrdMfrInfo(id, CurrentThreadContext.getCurrentSysCd(),CurrentThreadContext.getCurrentOrgCd());
	}

	@Override
	public boolean disAblePrdMfrInfo(Long id) throws BaseException {
		if(null == id){
			BaseLogUtils.newWebLogger("禁用厂商失败,主键参数为空").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_PROD_MANAGER_CD)
					.setWarning(false)
					.warn(LogExceptionEnum.COMMON_CODE_0002);
			throw new BaseException(BaseExceptionConstant.COMMON_0001,BaseExceptionConstant.COMMON_0001_NAME);
		}
		return this.mfrInfoApiService.disAblePrdMfrInfo(id, CurrentThreadContext.getCurrentSysCd(),CurrentThreadContext.getCurrentOrgCd());
	}

	@Override
	public List<MfrInfoVO> searchList(MfrInfoQueryCondition qc)
			throws BaseException {
		if(null==qc){
			qc = new MfrInfoQueryCondition();
		}
		List<MfrInfoDTO> dtoList = this.mfrInfoApiService.searchPrdMfrInfoList(qc);
		return MfrInfoVOTransform.toVOList(dtoList);
	}

	/*private List<MfrInfoVO> setDict(List<MfrInfoVO> voList) throws BaseException{
		if(CollectionUtils.isEmpty(voList)){
			return null;
		}
		//放款类型
		Map<String,String> payTypCdMap = this.sysDictionaryApiService.searchGroupToMap(CurrentThreadContext.getCurrentSysCd(),CurrentThreadContext.getCurrentOrgCd(),"MFR0001");
		for(MfrInfoVO vo : voList){
			if(CollectionUtils.isMapNotEmpty(payTypCdMap)&&payTypCdMap.containsKey(vo.getPayTypCd())){
				vo.setPayTypCdNm(payTypCdMap.get(vo.getPayTypCd()));
			}
		}
		return voList;
	}*/

	private MfrInfoVO setDict(MfrInfoVO vo) throws BaseException{
		if(null == vo){
			return null;
		}
		//放款类型
		Map<String,String> payTypCdMap = this.sysDictionaryApiService.searchGroupToMap(CurrentThreadContext.getCurrentSysCd(),CurrentThreadContext.getCurrentOrgCd(),"MFR0001");
		if(CollectionUtils.isMapNotEmpty(payTypCdMap)&&payTypCdMap.containsKey(vo.getPayTypCd())){
			vo.setPayTypCdNm(payTypCdMap.get(vo.getPayTypCd()));
		}
		return vo;
	}

	/**
	 * 查询数据字典
	 *
	 * @param grpCd 组代码
	 * @return
	 * @throws BaseException
	 */
	@Override
	public List<KeyValueVO> searchCdList(String grpCd) throws BaseException {
		return this.sysDictionaryApiService.getKvList(grpCd,CurrentThreadContext.getCurrentSysCd(),CurrentThreadContext.getCurrentOrgCd());
	}

	//厂商流程相关接口$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
	/**
	 * 通过厂商id 判断该厂商是否存在变更中流程
	 * @param id
	 * @return true 存在变更流程 false 不存在变更流程
	 */
	@Override
	public boolean checkMfrModFlowStatus(Long id) throws BaseException {
		boolean flag = false;
		MfrInfoModQC mfrInfoModQC = new MfrInfoModQC() ;
		mfrInfoModQC.setMfrId(id);
		mfrInfoModQC.setIsDel(BaseConstant.IS_YESNO_NO);
		mfrInfoModQC.setIsValid(BaseConstant.IS_YESNO_YES);
		mfrInfoModQC.setTabNm(MfrInfoConstant.MFR_INFO_FLOW_S_H_MFR_TAB);
		try {
			//是否加入最新记录查询
			List<MfrInfoModDTO> mfrInfoModDTOS = this.mfrInfoModApiService.searchMfrInfoModList(mfrInfoModQC);
			//变更记录ID LIST
			List<Long> mfrModIds = null;
			if (CollectionUtils.isNotEmpty(mfrInfoModDTOS)) {
				mfrModIds = new ArrayList<>(mfrInfoModDTOS.size());
				for (MfrInfoModDTO dto : mfrInfoModDTOS) {
					mfrModIds.add(dto.getId());
				}

				//审核状态 LIST
				List<String> audStsCdList = new ArrayList<>(4);
				audStsCdList.add(SplAudStsCdEnum.CHECKING.getStatus());
				audStsCdList.add(SplAudStsCdEnum.REJECT.getStatus());

				//业务类型 LIST
				List<String> busTypCdList = new ArrayList<>(2);
				busTypCdList.add(MfrInfoConstant.MFR_BASE_MOD_FLOW_BUS_TYP_CD);
				busTypCdList.add(MfrInfoConstant.MFR_PAY_TYP_MOD_FLOW_BUS_TYP_CD);

				//查询流程历史
				SysFlowSHQueryCondition shQueryCondition = new SysFlowSHQueryCondition();
				shQueryCondition.setDataIdList(mfrModIds);
				shQueryCondition.setBusTypList(busTypCdList);
				shQueryCondition.setWordsInTheTable(MfrInfoConstant.MFR_INFO_FLOW_S_H_MFR);
				shQueryCondition.setStatus(BaseConstant.IS_YESNO_YES);
				shQueryCondition.setSysCd(SplSystemConstant.FL_SYS_CD);
				shQueryCondition.setAudStsCdList(audStsCdList);
				try {
					List<SysFlowSHDTO> sysFlowSHDTOs = this.flowQueryApiService.searchFlowSHList(shQueryCondition);
					if (CollectionUtils.isNotEmpty(sysFlowSHDTOs)) {
						flag = true;
						BaseLogUtils.newWebLogger("存在厂商变更流程，流程信息").setLogOperType(LogOperEnum.RESP)
								.setSysCd(CurrentThreadContext.getCurrentSysCd())
								.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
								.setBussinessId(BusinessIdConstant.LOG_PROD_MANAGER_CD)
								.setWarning(false)
								.setKeys("sysFlowSHDTOs", JSONObject.toJSONString(sysFlowSHDTOs))
								.info();
					}
				} catch (RpcException rpc) {
					flag = true;
					BaseLogUtils.newWebLogger("查询流程历史远程调用异常RPCException，业务异常").setLogOperType(LogOperEnum.REQ)
							.setSysCd(CurrentThreadContext.getCurrentSysCd())
							.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
							.setBussinessId(BusinessIdConstant.LOG_PROD_MANAGER_CD)
							.setWarning(false)
							.setThrowable(rpc)
							.warn(LogExceptionEnum.COMMON_CODE_0002);
				} catch (BaseException be) {
					flag = true;
					BaseLogUtils.newWebLogger("查询流程历史异常BaseException，业务异常").setLogOperType(LogOperEnum.REQ)
							.setSysCd(CurrentThreadContext.getCurrentSysCd())
							.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
							.setBussinessId(BusinessIdConstant.LOG_PROD_MANAGER_CD)
							.setWarning(false)
							.setThrowable(be)
							.warn(LogExceptionEnum.COMMON_CODE_0002);
				} catch (Exception e) {
					flag = true;
					BaseLogUtils.newWebLogger("查询流程历史异常Exception，系统异常").setLogOperType(LogOperEnum.REQ)
							.setSysCd(CurrentThreadContext.getCurrentSysCd())
							.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
							.setBussinessId(BusinessIdConstant.LOG_PROD_MANAGER_CD)
							.setWarning(false)
							.setThrowable(e)
							.error(LogExceptionEnum.COMMON_CODE_0099);
				}
			}
		}catch (RpcException rpc) {
			flag = true;
			BaseLogUtils.newWebLogger("厂商最新变更记录查询远程调用异常RPCException，业务异常").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_PROD_MANAGER_CD)
					.setWarning(false)
					.setThrowable(rpc)
					.warn(LogExceptionEnum.COMMON_CODE_0002);
		} catch (BaseException be) {
			flag = true;
			BaseLogUtils.newWebLogger("厂商最新变更记录查询异常BaseException，业务异常").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_PROD_MANAGER_CD)
					.setWarning(false)
					.setThrowable(be)
					.warn(LogExceptionEnum.COMMON_CODE_0002);
		} catch (Exception e) {
			flag = true;
			BaseLogUtils.newWebLogger("厂商最新变更记录查询异常Exception，系统异常").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_PROD_MANAGER_CD)
					.setWarning(false)
					.setThrowable(e)
					.error(LogExceptionEnum.COMMON_CODE_0099);
		}
		return flag;
	}

	@Override
	public DataResultDTO addMfrAccessFlowStart(FlowStartParamsDTO flowStartParamsDTO) throws BaseException {
		if(StringUtils.isEmpty(flowStartParamsDTO.getCrtUsrId()) || StringUtils.isEmpty(flowStartParamsDTO.getBusinessKey())){
			BaseLogUtils.newWebLogger("用户ID和业务数据主键必须要存在!").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_PROD_MANAGER_CD)
					.setWarning(false)
					.warn(LogExceptionEnum.COMMON_CODE_0002);
			throw new BaseException(BaseExceptionConstant.COMMON_0001, "用户ID和业务数据主键必须要存在!");
		}
		return this.mfrInfoApiService.addMfrAccessFlowStart(flowStartParamsDTO);
	}

	/**
	 * 通过厂商id 判断该厂商是否已发起流程
	 *
	 * @param id
	 * @return true 存在变更流程 false 不存在变更流程
	 */
	@Override
	public boolean checkMfrInfoFlowStatus(Long id) throws BaseException {
		boolean flag = false;
		//审核状态 LIST
		List<String> audStsCdList = new ArrayList<>(4);
		audStsCdList.add(SplAudStsCdEnum.CHECKING.getStatus());
		audStsCdList.add(SplAudStsCdEnum.REJECT.getStatus());
		//业务类型 LIST
		List<String> busTypCdList = new ArrayList<>(2);
		busTypCdList.add(MfrInfoConstant.MFR_INFO_FLOW_BUS_TYP_CD);

		//查询流程历史
		SysFlowSHQueryCondition shQueryCondition = new SysFlowSHQueryCondition();
		shQueryCondition.setDataId(id);
		shQueryCondition.setBusTypList(busTypCdList);
		shQueryCondition.setWordsInTheTable(MfrInfoConstant.MFR_INFO_FLOW_S_H_MFR);
		shQueryCondition.setStatus(BaseConstant.IS_YESNO_YES);
		shQueryCondition.setSysCd(SplSystemConstant.FL_SYS_CD);
		shQueryCondition.setAudStsCdList(audStsCdList);
		try{
			List<SysFlowSHDTO> sysFlowSHDTOs = this.flowQueryApiService.searchFlowSHList(shQueryCondition);
			if(CollectionUtils.isNotEmpty(sysFlowSHDTOs)){
				flag = true ;
				BaseLogUtils.newWebLogger("存在准入流程，流程信息").setLogOperType(LogOperEnum.RESP)
						.setSysCd(CurrentThreadContext.getCurrentSysCd())
						.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
						.setBussinessId(BusinessIdConstant.LOG_PROD_MANAGER_CD)
						.setWarning(false)
						.setKeys("sysFlowSHDTOs", JSONObject.toJSONString(sysFlowSHDTOs))
						.info();
			}
		}catch (RpcException rpc){
			flag = true ;
			BaseLogUtils.newWebLogger("查询流程历史远程调用异常RPCException，业务异常").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_PROD_MANAGER_CD)
					.setWarning(false)
					.setThrowable(rpc)
					.warn(LogExceptionEnum.COMMON_CODE_0002);
		}catch (BaseException be){
			flag = true ;
			BaseLogUtils.newWebLogger("查询流程历史异常BaseException，业务异常").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_PROD_MANAGER_CD)
					.setWarning(false)
					.setThrowable(be)
					.warn(LogExceptionEnum.COMMON_CODE_0002);
		}catch (Exception e){
			flag = true ;
			BaseLogUtils.newWebLogger("查询流程历史异常Exception，系统异常").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_PROD_MANAGER_CD)
					.setWarning(false)
					.setThrowable(e)
					.error(LogExceptionEnum.COMMON_CODE_0099);
		}
		return flag;
	}
	
	@Override
	public List<MfrFlowSHVO> searchMfrFlowList(Long mfrId) throws BaseException {
		
		return MfrFlowSHVOTransform.toVOList(this.mfrInfoApiService.searchMfrFlowList(mfrId,CurrentThreadContext.getCurrentSysCd()));
	}

	/**
	 * 通过厂商id 判断该厂商是否在登陆人所属事业部 存在放款方式变更流程
	 */
	@Override
	public boolean checkMfrPayTypModFlowStatus(Long id, String buOrgCd) throws BaseException {
		// TODO Auto-generated method stub
		boolean flag = false;
		MfrOrgRQC mfrOrgRQC = new MfrOrgRQC();
		mfrOrgRQC.setBuOrgCd(buOrgCd);
		mfrOrgRQC.setIsDel(BaseConstant.IS_YESNO_NO);
		mfrOrgRQC.setIsValid(BaseConstant.IS_YESNO_YES);
		mfrOrgRQC.setMfrId(id);
		try {
			List<MfrOrgRDTO> mfrOrgRDTOS = this.mfrOrgRApiService.searchMfrOrgRDTOList(mfrOrgRQC);
			if(CollectionUtils.isNotEmpty(mfrOrgRDTOS)){
				MfrOrgRDTO mfrOrgRDTO = mfrOrgRDTOS.get(0);
				//是否加入最新记录查询
				MfrInfoModQC mfrInfoModQC = new MfrInfoModQC() ;
				mfrInfoModQC.setMfrId(mfrOrgRDTO.getId());
				mfrInfoModQC.setTabNm(MfrInfoConstant.MFR_INFO_FLOW_S_H_MFR_TAB);
				mfrInfoModQC.setIsPayTypMdf(BaseConstant.IS_YESNO_YES);
				mfrInfoModQC.setIsDel(BaseConstant.IS_YESNO_NO);
				mfrInfoModQC.setIsValid(BaseConstant.IS_YESNO_YES);
				mfrInfoModQC.setIsNew(BaseConstant.IS_YESNO_YES);
				List<MfrInfoModDTO> mfrInfoModDTOS = this.mfrInfoModApiService.searchMfrInfoModList(mfrInfoModQC);
				if (CollectionUtils.isNotEmpty(mfrInfoModDTOS)) {
					MfrInfoModDTO dto = mfrInfoModDTOS.get(0);

					//审核状态 LIST
					List<String> audStsCdList = new ArrayList<>(4);
					audStsCdList.add(SplAudStsCdEnum.CHECKING.getStatus());
					audStsCdList.add(SplAudStsCdEnum.REJECT.getStatus());

					//业务类型 LIST
					List<String> busTypCdList = new ArrayList<>(2);
					busTypCdList.add(MfrInfoConstant.MFR_PAY_TYP_MOD_FLOW_BUS_TYP_CD);

					//查询流程历史
					SysFlowSHQueryCondition shQueryCondition = new SysFlowSHQueryCondition();
					shQueryCondition.setDataId(dto.getId());
					shQueryCondition.setBusTypList(busTypCdList);
					shQueryCondition.setWordsInTheTable(MfrInfoConstant.MFR_INFO_FLOW_S_H_MFR);
					shQueryCondition.setStatus(BaseConstant.IS_YESNO_YES);
					shQueryCondition.setSysCd(SplSystemConstant.FL_SYS_CD);
					shQueryCondition.setAudStsCdList(audStsCdList);
					try {
						List<SysFlowSHDTO> sysFlowSHDTOs = this.flowQueryApiService.searchFlowSHList(shQueryCondition);
						if (CollectionUtils.isNotEmpty(sysFlowSHDTOs)) {
							flag = true;
							BaseLogUtils.newWebLogger("存在厂商变更流程").setLogOperType(LogOperEnum.RESP)
									.setSysCd(CurrentThreadContext.getCurrentSysCd())
									.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
									.setBussinessId(BusinessIdConstant.LOG_PROD_MANAGER_CD)
									.setWarning(false)
									.setKeys("sysFlowSHDTOs", JSONObject.toJSONString(sysFlowSHDTOs))
									.info();
						}
					} catch (RpcException rpc) {
						flag = true;
						BaseLogUtils.newWebLogger("查询流程历史远程调用异常RPCException，业务异常").setLogOperType(LogOperEnum.REQ)
								.setSysCd(CurrentThreadContext.getCurrentSysCd())
								.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
								.setBussinessId(BusinessIdConstant.LOG_PROD_MANAGER_CD)
								.setWarning(false)
								.setThrowable(rpc)
								.warn(LogExceptionEnum.COMMON_CODE_0002);
					} catch (BaseException be) {
						flag = true;
						BaseLogUtils.newWebLogger("查询流程历史异常BaseException，业务异常").setLogOperType(LogOperEnum.REQ)
								.setSysCd(CurrentThreadContext.getCurrentSysCd())
								.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
								.setBussinessId(BusinessIdConstant.LOG_PROD_MANAGER_CD)
								.setWarning(false)
								.setThrowable(be)
								.warn(LogExceptionEnum.COMMON_CODE_0002);
					} catch (Exception e) {
						flag = true;
						BaseLogUtils.newWebLogger("查询流程历史异常Exception，系统异常").setLogOperType(LogOperEnum.REQ)
								.setSysCd(CurrentThreadContext.getCurrentSysCd())
								.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
								.setBussinessId(BusinessIdConstant.LOG_PROD_MANAGER_CD)
								.setWarning(false)
								.setThrowable(e)
								.error(LogExceptionEnum.COMMON_CODE_0099);
					}
				}
			}
		}catch (RpcException rpc) {
			flag = true;
			BaseLogUtils.newWebLogger("厂商最新变更记录查询远程调用异常RPCException，业务异常").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_PROD_MANAGER_CD)
					.setWarning(false)
					.setThrowable(rpc)
					.warn(LogExceptionEnum.COMMON_CODE_0002);
		} catch (BaseException be) {
			flag = true;
			BaseLogUtils.newWebLogger("厂商最新变更记录查询异常BaseException，业务异常").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_PROD_MANAGER_CD)
					.setWarning(false)
					.setThrowable(be)
					.warn(LogExceptionEnum.COMMON_CODE_0002);
		} catch (Exception e) {
			flag = true;
			BaseLogUtils.newWebLogger("厂商最新变更记录查询异常Exception，系统异常").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_PROD_MANAGER_CD)
					.setWarning(false)
					.setThrowable(e)
					.error(LogExceptionEnum.COMMON_CODE_0099);
		}
		return flag;
	}

	/**
	 * 通过厂商id 判断该厂商是否存在基础信息变更流程
	 */
	@Override
	public boolean checkMfrBaseModFlowStatus(Long id) throws BaseException {
		// TODO Auto-generated method stub
		boolean flag = false;
		MfrInfoModQC mfrInfoModQC = new MfrInfoModQC() ;
		mfrInfoModQC.setMfrId(id);
		mfrInfoModQC.setTabNm(MfrInfoConstant.MFR_INFO_FLOW_S_H_MFR_TAB);
		mfrInfoModQC.setIsBscMdf(BaseConstant.IS_YESNO_YES);
		mfrInfoModQC.setIsDel(BaseConstant.IS_YESNO_NO);
		mfrInfoModQC.setIsValid(BaseConstant.IS_YESNO_YES);
		mfrInfoModQC.setIsNew(BaseConstant.IS_YESNO_YES);
		try {
			//是否加入最新记录查询
			List<MfrInfoModDTO> mfrInfoModDTOS = this.mfrInfoModApiService.searchMfrInfoModList(mfrInfoModQC);
			if (CollectionUtils.isNotEmpty(mfrInfoModDTOS)) {
				MfrInfoModDTO dto = mfrInfoModDTOS.get(0);

				//审核状态 LIST
				List<String> audStsCdList = new ArrayList<>(4);
				audStsCdList.add(SplAudStsCdEnum.CHECKING.getStatus());
				audStsCdList.add(SplAudStsCdEnum.REJECT.getStatus());

				//业务类型 LIST
				List<String> busTypCdList = new ArrayList<>(2);
				busTypCdList.add(MfrInfoConstant.MFR_BASE_MOD_FLOW_BUS_TYP_CD);

				//查询流程历史
				SysFlowSHQueryCondition shQueryCondition = new SysFlowSHQueryCondition();
				shQueryCondition.setDataId(dto.getId());
				shQueryCondition.setBusTypList(busTypCdList);
				shQueryCondition.setWordsInTheTable(MfrInfoConstant.MFR_INFO_FLOW_S_H_MFR);
				shQueryCondition.setStatus(BaseConstant.IS_YESNO_YES);
				shQueryCondition.setSysCd(SplSystemConstant.FL_SYS_CD);
				shQueryCondition.setAudStsCdList(audStsCdList);
				try {
					List<SysFlowSHDTO> sysFlowSHDTOs = this.flowQueryApiService.searchFlowSHList(shQueryCondition);
					if (CollectionUtils.isNotEmpty(sysFlowSHDTOs)) {
						flag = true;
						BaseLogUtils.newWebLogger("存在厂商变更流程").setLogOperType(LogOperEnum.RESP)
								.setSysCd(CurrentThreadContext.getCurrentSysCd())
								.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
								.setBussinessId(BusinessIdConstant.LOG_PROD_MANAGER_CD)
								.setWarning(false)
								.setKeys("sysFlowSHDTOs", JSONObject.toJSONString(sysFlowSHDTOs))
								.info();
					}
				} catch (RpcException rpc) {
					flag = true;
					BaseLogUtils.newWebLogger("查询流程历史远程调用异常RPCException，业务异常").setLogOperType(LogOperEnum.REQ)
							.setSysCd(CurrentThreadContext.getCurrentSysCd())
							.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
							.setBussinessId(BusinessIdConstant.LOG_PROD_MANAGER_CD)
							.setWarning(false)
							.setThrowable(rpc)
							.warn(LogExceptionEnum.COMMON_CODE_0002);
				} catch (BaseException be) {
					flag = true;
					BaseLogUtils.newWebLogger("查询流程历史异常BaseException，业务异常").setLogOperType(LogOperEnum.REQ)
							.setSysCd(CurrentThreadContext.getCurrentSysCd())
							.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
							.setBussinessId(BusinessIdConstant.LOG_PROD_MANAGER_CD)
							.setWarning(false)
							.setThrowable(be)
							.warn(LogExceptionEnum.COMMON_CODE_0002);
				} catch (Exception e) {
					flag = true;
					BaseLogUtils.newWebLogger("查询流程历史异常Exception，系统异常").setLogOperType(LogOperEnum.REQ)
							.setSysCd(CurrentThreadContext.getCurrentSysCd())
							.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
							.setBussinessId(BusinessIdConstant.LOG_PROD_MANAGER_CD)
							.setWarning(false)
							.setThrowable(e)
							.error(LogExceptionEnum.COMMON_CODE_0099);
				}
			}
		}catch (RpcException rpc) {
			flag = true;
			BaseLogUtils.newWebLogger("厂商最新变更记录查询远程调用异常RPCException，业务异常").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_PROD_MANAGER_CD)
					.setWarning(false)
					.setThrowable(rpc)
					.warn(LogExceptionEnum.COMMON_CODE_0002);
		} catch (BaseException be) {
			flag = true;
			BaseLogUtils.newWebLogger("厂商最新变更记录查询异常BaseException，业务异常").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_PROD_MANAGER_CD)
					.setWarning(false)
					.setThrowable(be)
					.warn(LogExceptionEnum.COMMON_CODE_0002);
		} catch (Exception e) {
			flag = true;
			BaseLogUtils.newWebLogger("厂商最新变更记录查询异常Exception，系统异常").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_PROD_MANAGER_CD)
					.setWarning(false)
					.setThrowable(e)
					.error(LogExceptionEnum.COMMON_CODE_0099);
		}
		return flag;
	}

	/**
	 * 是否应该发起变更流程
	 */
	@Override
	public boolean getChangeStatus(MfrInfoDTO dto, String isBsc) throws BaseException {
		// TODO Auto-generated method stub
		MfrInfoDTO infoDTO = this.mfrInfoApiService.selectPrdMfrInfoById(dto.getId(), CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd());
		if(null != infoDTO){
			if("0".equals(isBsc)){
				if(infoDTO.getPayTypCd() == null || !infoDTO.getPayTypCd().equals(dto.getPayTypCd())){
					return true;
				}
			}else{
				BaseMfrBscInfoDTO bscInfoDTO = new BaseMfrBscInfoDTO();
				boolean flag = this.mfrInfoIsChange(bscInfoDTO, infoDTO, dto);
				if(flag){
					return true;
				}else{
					List<MfrRlPsnDTO> psnDTOs = dto.getMfrRlPsnList();
					List<MfrRlPsnDTO> rlPsnDTOs = infoDTO.getMfrRlPsnList();
					if(psnDTOs.size() != rlPsnDTOs.size()){
						return true;
					}else{
						for (MfrRlPsnDTO psnDTO : psnDTOs) {
							boolean status = true;
							for (MfrRlPsnDTO rlPsnDTO : rlPsnDTOs) {
								if(rlPsnDTO.getId().equals(psnDTO.getId())){
									status = false;
									BaseMfrRlPsnDTO baseMfrRlPsnDTO = new BaseMfrRlPsnDTO();
									boolean success = this.mfrInfoIsChange(baseMfrRlPsnDTO, rlPsnDTO, psnDTO);
									if(success){
										return true;
									}else{
										continue;
									}
								}
							}
							if(status){
								return true;
							}
						}
					}
				}
			}
		}
		return false;
	}

	/**
	 * 是否变更
	 * @param obj   加filedApply注解的类
	 * @param objBef  老数据
	 * @param objAft  新数据
	 * @return
	 * @throws BaseException
	 */
	private boolean mfrInfoIsChange(Object obj,Object objBef,Object objAft) throws BaseException {
		Field[] fields = obj.getClass().getDeclaredFields();
		for (Field field : fields) {
			FieldApply fieldApply = field.getAnnotation(FieldApply.class);
			if (fieldApply == null || !fieldApply.isApplySign()){
				continue;
			}else{
				String fieldNm = fieldApply.fieldNm();
				// 字符串首字母大写
				char[] cs = fieldNm.toCharArray();
				cs[0] -= 32;
				// 调用get方法
				Method methodBef = null;
				Method methodAft = null;
				try {
					methodBef = objBef.getClass().getMethod("get" + String.valueOf(cs));
					methodAft = objAft.getClass().getMethod("get" + String.valueOf(cs));
				} catch (NoSuchMethodException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (SecurityException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				// 得到值
				String invokeBef = null;
				String invokeAft = null;
				try {
					invokeBef = String.valueOf(methodBef.invoke(objBef));
					invokeAft = String.valueOf(methodAft.invoke(objAft));
					if(null != invokeAft && !invokeAft.equals(invokeBef)){
						return true;
					}
				} catch (IllegalAccessException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (IllegalArgumentException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (InvocationTargetException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
		return false;
	}

	/**
	 * 发起厂商变更流程
	 */
	@Override
	public DataResultDTO modifyMfrInfoFlowStart(FlowStartParamsDTO flowStartParamsDTO) throws BaseException {
		// TODO Auto-generated method stub
		if(StringUtils.isEmpty(flowStartParamsDTO.getCrtUsrId()) || StringUtils.isEmpty(flowStartParamsDTO.getBusinessKey())){
			BaseLogUtils.newWebLogger("用户ID和业务数据主键必须要存在!").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_PROD_MANAGER_CD)
					.setWarning(false)
					.warn(LogExceptionEnum.COMMON_CODE_0002);
			throw new BaseException(BaseExceptionConstant.COMMON_0001, "用户ID和业务数据主键必须要存在!");
		}
		return this.mfrInfoModApiService.modifyMfrInfoFlowStart(flowStartParamsDTO);
	}

	/**
	 * 同步修改基础信息 新增修改主表 修改详细表
	 */
	@Override
	public Long addMfrInfoMod(MfrInfoModDTO mfrInfoModDTO, MfrInfoDTO dto) throws BaseException {
		// TODO Auto-generated method stub
		if(null == mfrInfoModDTO || null == dto){
			BaseLogUtils.newWebLogger("同步修改基础信息新增修改主表修改详细表参数不能为空!").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_PROD_MANAGER_CD)
					.setWarning(false)
					.warn(LogExceptionEnum.COMMON_CODE_0002);
			throw new BaseException(BaseExceptionConstant.COMMON_0001, BaseExceptionConstant.COMMON_0001_NAME);
		}
		return this.mfrInfoModApiService.addMfrInfoMod(mfrInfoModDTO, dto, CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd());
	}

	/**
	 * 流程发起成功 修改非流程字段
	 */
	@Override
	public boolean modifyMfrBscInfoFlow(MfrInfoDTO mfrInfoDTO) throws BaseException {
		// TODO Auto-generated method stub
		if(null == mfrInfoDTO){
			BaseLogUtils.newWebLogger("修改产品厂商信息失败,厂商对象参数为空").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_PROD_MANAGER_CD)
					.setWarning(false)
					.warn(LogExceptionEnum.COMMON_CODE_0002);
			throw new BaseException(BaseExceptionConstant.COMMON_0001, BaseExceptionConstant.COMMON_0001_NAME);
		}
		MfrInfoDTO dto = this.mfrInfoApiService.selectPrdMfrInfoById(mfrInfoDTO.getId(), CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd());
		if(null == dto){
			BaseLogUtils.newWebLogger("修改产品厂商信息失败,厂商对象不存在").setLogOperType(LogOperEnum.RESP)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_PROD_MANAGER_CD)
					.setWarning(false)
					.warn(LogExceptionEnum.COMMON_CODE_0002);
			throw new BaseException(BaseExceptionConstant.COMMON_0001, BaseExceptionConstant.COMMON_0001_NAME);
		}
		Field[] fields = BaseMfrBscInfoDTO.class.getDeclaredFields();
		for (Field field : fields) {
			FieldApply fieldApply = field.getAnnotation(FieldApply.class);
			if (fieldApply == null || !fieldApply.isApplySign()){
				continue;
			}else{
				String fieldNm = fieldApply.fieldNm();
				// 字符串首字母大写
				char[] cs = fieldNm.toCharArray();
				cs[0] -= 32;
				// 调用get方法
				Method methodBef = null;
				Method methodAft = null;
				try {
					methodBef = dto.getClass().getMethod("get" + String.valueOf(cs));
					methodAft = mfrInfoDTO.getClass().getMethod("get" + String.valueOf(cs));
				} catch (NoSuchMethodException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (SecurityException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				// 得到值
				String invokeBef = null;
				String invokeAft = null;
				try {
					invokeBef = String.valueOf(methodBef.invoke(dto));
					invokeAft = String.valueOf(methodAft.invoke(mfrInfoDTO));
				} catch (IllegalAccessException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (IllegalArgumentException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (InvocationTargetException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				if(null != invokeAft && !invokeAft.equals(invokeBef)){
					try {
						Field fieldSet = BaseMfrBscInfoDTO.class.getDeclaredField(fieldNm);
						fieldSet.setAccessible(true);
						try {
							fieldSet.set(mfrInfoDTO, invokeBef);
						} catch (IllegalArgumentException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						} catch (IllegalAccessException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
					} catch (NoSuchFieldException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					} catch (SecurityException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
			}
		}
		mfrInfoDTO.setPayTypCd(null);
		mfrInfoDTO.setPayTypCdNm(null);
		mfrInfoDTO.setMfrRlPsnList(null);
		return this.mfrInfoApiService.modifyPrdMfrInfo(mfrInfoDTO, CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd());
	}

	/**
	 * 流程发起成功 修改非流程字段
	 */
	@Override
	public boolean removeMfrInfoMod(Long modId) throws BaseException {
		// TODO Auto-generated method stub
		if(null == modId){
			BaseLogUtils.newWebLogger("移除厂商修改信息失败,参数为空").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_PROD_MANAGER_CD)
					.setWarning(false)
					.warn(LogExceptionEnum.COMMON_CODE_0002);
			throw new BaseException(BaseExceptionConstant.COMMON_0001, BaseExceptionConstant.COMMON_0001_NAME);
		}
		return this.mfrInfoModApiService.removeMfrInfoModDTOById(modId, CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd());
	}

	@Override
	public boolean modifyBscAgain(MfrInfoDTO entity, String modId) throws BaseException {
		if(null == entity || StringUtils.isEmpty(modId)){
			BaseLogUtils.newWebLogger("修改厂商失败,厂商对象参数为空").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_PROD_MANAGER_CD)
					.setWarning(false)
					.warn(LogExceptionEnum.COMMON_CODE_0002);
			throw new BaseException(BaseExceptionConstant.COMMON_0001,BaseExceptionConstant.COMMON_0001_NAME);
		}
		MfrInfoModDTO mfrInfoModDTO = this.mfrInfoModApiService.selectMfrInfoModDTOById(Long.valueOf(modId),CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd(),"","");
		if(null != mfrInfoModDTO){
			if(mfrInfoModDTO.getIsPayTypMdf().equals(BaseConstant.IS_YESNO_YES)){
				MfrInfoModDtlQC mfrInfoModDtlQC = new MfrInfoModDtlQC();
				mfrInfoModDtlQC.setModId(Long.valueOf(modId));
				mfrInfoModDtlQC.setIsValid(BaseConstant.IS_YESNO_YES);
				mfrInfoModDtlQC.setIsDel(BaseConstant.IS_YESNO_NO);
				List<MfrInfoModDtlDTO> mfrInfoModDtlDTOS = this.mfrInfoModDtlApiService.searchMfrInfoModDtlDTOList(mfrInfoModDtlQC);
				MfrInfoModDtlDTO mfrInfoModDtlDTO = mfrInfoModDtlDTOS.get(0);
				mfrInfoModDtlDTO.setModConAft(entity.getPayTypCd());
				this.mfrInfoModDtlApiService.modifyMfrInfoModDtlDTO(mfrInfoModDtlDTO,CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd(),"","");
			}else{
				this.mfrInfoModApiService.modifyBscAgain(entity,Long.valueOf(modId),CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd(),CurrentThreadContext.getCurrentUserId(),CurrentThreadContext.getCurrentUserName());
				this.modifyMfrBscInfoFlow(entity);
			}
		}
		return true;
	}

	@Override
	public MfrInfoVO selectMfrFlowById(Long id, Long modId,String currentOrgCd) throws BaseException {
		if (StringUtils.isEmpty(id) || StringUtils.isEmpty(modId)) {
			BaseLogUtils.newWebLogger("获取厂商数据,主键参数为空").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_PROD_MANAGER_CD)
					.setWarning(false)
					.warn(LogExceptionEnum.COMMON_CODE_0002);
			throw new BaseException(BaseExceptionConstant.COMMON_0001, BaseExceptionConstant.COMMON_0001_NAME);
		}
		MfrInfoDTO mfrInfoDTO = this.mfrInfoApiService.selectPrdMfrInfoById(id,CurrentThreadContext.getCurrentSysCd(),currentOrgCd);
		MfrInfoVO mfrInfoVO = MfrInfoVOTransform.toVO(mfrInfoDTO);
		MfrInfoModDTO mfrInfoModDTO = this.mfrInfoModApiService.selectMfrInfoModDTOById(modId,CurrentThreadContext.getCurrentSysCd(),CurrentThreadContext.getCurrentOrgCd(),"","");
		MfrInfoModDtlQC mfrInfoModDtlQC = new MfrInfoModDtlQC();
		mfrInfoModDtlQC.setModId(modId);
		mfrInfoModDtlQC.setIsDel(BaseConstant.IS_YESNO_NO);
		List<MfrInfoModDtlDTO> mfrInfoModDtlDTOS = this.mfrInfoModDtlApiService.searchMfrInfoModDtlDTOList(mfrInfoModDtlQC);
		if(null != mfrInfoModDTO){
			if(mfrInfoModDTO.getIsPayTypMdf() == BaseConstant.IS_YESNO_YES){
				for (MfrInfoModDtlDTO mfrInfoModDtlDTO : mfrInfoModDtlDTOS) {
					if(mfrInfoModDtlDTO.getModAttrFiled().equals("payTypCd")){
						mfrInfoVO.setPayTypCd(mfrInfoModDtlDTO.getModConAft());
						//放款类型
						Map<String,String> payTypCdMap = this.sysDictionaryApiService.searchGroupToMap(CurrentThreadContext.getCurrentSysCd(),CurrentThreadContext.getCurrentOrgCd(),"MFR0001");
						mfrInfoVO.setPayTypCdNm(payTypCdMap.get(mfrInfoVO.getPayTypCd()));
					}
				}
			}else {
				for (MfrInfoModDtlDTO mfrInfoModDtlDTO : mfrInfoModDtlDTOS) {
					if (mfrInfoModDtlDTO.getTabNm().equals(MfrInfoConstant.MFR_INFO_FLOW_S_H_MFR_TAB)) {
						Field field = null;
						try {
							field = BaseMfrBscInfoVO.class.getDeclaredField(mfrInfoModDtlDTO.getModAttrFiled());
						} catch (NoSuchFieldException e) {
							e.printStackTrace();
						}
						field.setAccessible(true);
						try {
							field.set((Object) mfrInfoVO, mfrInfoModDtlDTO.getModConAft());
						} catch (IllegalAccessException e) {
							e.printStackTrace();
						}
					}
				}
			}
		}
		return mfrInfoVO;
	}
	
	@Override
	public boolean batchAddFileList(List<SysUlFilesRecVO> fileList)
			throws BaseException {
		if(CollectionUtils.isEmpty(fileList)){
			throw new BaseException(BaseExceptionConstant.COMMON_0001, BaseExceptionConstant.COMMON_0001_NAME);
		}
		return this.mfrInfoApiService.batchAddFileList(SysUlFilesRecVOTransform.toDTOList(fileList));
	}

	@Override
	public boolean modifyMfrInfoModDtlFileList(Long mfrId, Long modId) throws BaseException {
		return this.mfrInfoModApiService.modifyMfrInfoModDtlFileList(mfrId,modId);
	}

	@Override
	public List<KeyValueVO> searchBrandList(String code) throws BaseException {
		return this.getKvList(code);
	}
	
	/**
	 * 根据字典中代码组值获取组员集合
	 * @param grpCd 代码组值
	 * @return 集合
	 */
	private List<KeyValueVO> getKvList(String grpCd){
		List<KeyValueVO> kvList = new ArrayList<>();
		try {
			List<SysDictionaryDTO> sysDictionaryDTOList = this.sysDictionaryApiService.searchGroup(CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd(), grpCd);
			if(CollectionUtils.isNotEmpty(sysDictionaryDTOList)){
				for (SysDictionaryDTO sysDictionaryDTO : sysDictionaryDTOList) {
					KeyValueVO keyValueVO = new KeyValueVO();
					keyValueVO.setKey(sysDictionaryDTO.getCode());
					keyValueVO.setValue(sysDictionaryDTO.getCodeNm());
					kvList.add(keyValueVO);
				}
			}
		} catch (BaseException e) {
			BaseLogUtils.newWebLogger("获取字典项组失败，业务异常").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_PROD_MANAGER_CD)
					.setWarning(false)
					.setThrowable(e)
					.warn(LogExceptionEnum.COMMON_CODE_0002);
		} catch (Exception e) {
			BaseLogUtils.newWebLogger("获取字典项组失败，系统异常").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_PROD_MANAGER_CD)
					.setWarning(false)
					.setThrowable(e)
					.error(LogExceptionEnum.COMMON_CODE_0099);
		}
		return kvList;
	}
	
	@Override
	public List<KeyValueVO> searchBuOrgCdList() throws BaseException {
		List<SysOrgDTO> dtoList = this.sysOrgApiService.searchListByOrgTypCd(CurrentThreadContext.getFlServiceSysCd());
		List<KeyValueVO> kvList = new ArrayList<KeyValueVO>();
		if(CollectionUtils.isNotEmpty(dtoList)){
			for (SysOrgDTO dto : dtoList) {
				KeyValueVO kv = new KeyValueVO();
				kv.setKey(dto.getOrgCd());
				kv.setValue(dto.getOrgDispNm());
				kvList.add(kv);
			}
		}
		return kvList;
	}

	@Override
	public Pager searchListPageByMask(Pager page, int isMask) throws BaseException {
		if(null == page){
			page = new Pager();
		}
		page = this.mfrInfoApiService.searchListPageByMask(page,isMask,CurrentThreadContext.getCurrentSysCd(),CurrentThreadContext.getCurrentOrgCd());
		List<MfrInfoDTO> resultList = (List<MfrInfoDTO>) page.getResultList();
		BaseLogUtils.newWebLogger("服务层返回的查询结果").setLogOperType(LogOperEnum.RESP)
				.setSysCd(CurrentThreadContext.getCurrentSysCd())
				.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
				.setBussinessId(BusinessIdConstant.LOG_PROD_MANAGER_CD)
				.setWarning(false)
				.setKeys("resultList", JSONObject.toJSONString(resultList))
				.info();
		page.setResultList(MfrInfoVOTransform.toVOList(resultList));
		return page;
	}

	@Override
	public MfrInfoVO selectByIdAndMask(Long id, int isMask, String currentOrgCd) throws BaseException {
		if(StringUtils.isEmpty(id)){
			BaseLogUtils.newWebLogger("根据主键查询厂商信息失败,主键参数为空").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_PROD_MANAGER_CD)
					.setWarning(false)
					.warn(LogExceptionEnum.COMMON_CODE_0002);
			throw new BaseException(BaseExceptionConstant.COMMON_0001,BaseExceptionConstant.COMMON_0001_NAME);
		};
		MfrInfoDTO dto = this.mfrInfoApiService.selectPrdMfrInfoByIdAndMask(id,isMask,CurrentThreadContext.getCurrentSysCd(),currentOrgCd);
		return this.setDict(MfrInfoVOTransform.toVO(dto));
	}


}